#include <iostream>
#include <chrono>
#include <random>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#define VNAME(name) (#name)
#define debug(x) {int debugx = x; std::cout << " (" << VNAME(x) << ": " << (debugx) << ")\n";}
#define F_(n) cout << fixed << setprecision(n)
#ifndef ONLINE_JUDGE
#else
	#define endl '\n'
#endif
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
bool _OJ_Flag = true;
static int __ = []() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    return 0;
}();//*/
char arr[N] = {1};
int go[N];
int solve(int n) {
    LL ans = 0;
    for (int i = 1; i <= n; ++ i) {
        cin >> arr[i], arr[i] ^= '0';
        if (arr[i] == 1 && arr[i - 1] == 1) go[i] = go[i - 1] == 0 ? i - 1 : go[i - 1]; 
    }
    for (int i = 1; i <= n; ++ i) {
        int v = 1;
        for (int j = i; j; ) {
            v *= arr[j];
            //debug(v); debug(i - j + 1);
            if (v == i - j + 1) ans ++;
            if (v > i) break;
            if (go[j]) {
                if (v > i - j + 1 && v < i - go[j] + 1) ans ++;
                j = go[j];
            } else j --;
        }
    }
    return ans;
}
signed main() {
    #ifndef ONLINE_JUDGE
		_OJ_Flag = false; //freopen("C:\\Users\\lenovo\\Desktop\\in.in", "r", stdin);
	#endif
    int t = 1;
    //cin >> t;
    while (t --) {
        int n, m;
        cin >> n;
        cout << solve(n) << endl;
        //debug(solve(n));
    }
    #ifndef ONLINE_JUDGE
		system("pause");
	#endif
    return 0;
}